<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <%@ include file="/common/plateform/include/common-base.jsp" %>
    <title>数据表管理</title>
</head>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

    <!-- top start -->
    <%@include file="/common/plateform/top.jsp" %>
    <!-- top end -->

    <!-- left start -->
    <%@include file="/common/plateform/left-project.jsp" %>
    <!-- left end-->

    <!-- Main start -->
    <div class="content-wrapper">
        <!-- Main start -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12 ibox">

                    <!--搜索  start -->
                    <div class="box box-info collapsed-box">

                        <!--搜索title  start -->
                        <div class="box-header with-border">
                            <h3 class="box-title"><i class="fa fa-search"></i> 搜索查询</h3>
                            <div class="box-tools pull-right">
                                <button type="button" class="btn btn-box-tool"
                                        data-widget="collapse"><i class="fa fa-plus"></i></button>
                            </div>
                        </div>
                        <div class="hidden">
                            <form id="addSysParamForm" action="javascript:void(0)">
                                <input type="hidden" name="ifBatch" value="T"/>
                                <input type="text" name="pageName" value="sys-param-manager"/>
                                <input type="text" name="formName" value="addFormBatch"/>
                                <input type="text" name="sysParamManager.splitAttr" value="sysName"/>
                                <table>
                                    <tr>
                                        <td><input type="text" name="sysParamManager.sysName"
                                                   value=""/></td>
                                        <td><input type="text" name="sysParamManager.pageName"
                                                   value="[pageName]"/></td>
                                        <td><input type="text" name="sysParamManager.formName"
                                                   value="addForm"/></td>
                                        <td><input type="text" name="sysParamManager.modelTypes"
                                                   value="i_[objName]"/></td>
                                        <td><input type="text" name="sysParamManager.resultName"
                                                   value=""/></td>
                                    </tr>
                                    <tr>
                                        <td><input type="text" name="sysParamManager.sysName"
                                                   value=""/></td>
                                        <td><input type="text" name="sysParamManager.pageName"
                                                   value="[pageName]"/></td>
                                        <td><input type="text" name="sysParamManager.formName"
                                                   value="delForm"/></td>
                                        <td><input type="text" name="sysParamManager.modelTypes"
                                                   value="d_[objName]"/></td>
                                        <td><input type="text" name="sysParamManager.resultName"
                                                   value=""/></td>
                                    </tr>
                                    <tr>
                                        <td><input type="text" name="sysParamManager.sysName"
                                                   value=""/></td>
                                        <td><input type="text" name="sysParamManager.pageName"
                                                   value="[pageName]"/></td>
                                        <td><input type="text" name="sysParamManager.formName"
                                                   value="editForm"/></td>
                                        <td><input type="text" name="sysParamManager.modelTypes"
                                                   value="u_[objName]"/></td>
                                        <td><input type="text" name="sysParamManager.resultName"
                                                   value=""/></td>
                                    </tr>
                                    <tr>
                                        <td><input type="text" name="sysParamManager.sysName"
                                                   value=""/></td>
                                        <td><input type="text" name="sysParamManager.pageName"
                                                   value="[pageName]"/></td>
                                        <td><input type="text" name="sysParamManager.formName"
                                                   value="searchForm"/></td>
                                        <td><input type="text" name="sysParamManager.modelTypes"
                                                   value="s_[objName]"/></td>
                                        <td><input type="text" name="sysParamManager.resultName"
                                                   value="T"/></td>
                                    </tr>
                                </table>
                            </form>
                        </div>
                        <!--搜索title  end -->
                        <div class="box-body">
                            <form id="searchForm" class="form-horizontal" action="javascript:;">
                                <input type="hidden" name="pageName" value="objName-table"/>
                                <input type="hidden" name="formName" value="searchForm"/>
                                <input type="hidden" name="orderBy" value="info_table_name"/>
                                <input type="hidden" id="searchForm_sysName" name="sortInfo.w_sysName"/>
                                <table class="table">
                                    <tbody>
                                        <tr>
                                            <td class="text-right"><label class="control-label">表名前缀：</label></td>
                                            <td><input type="text" class="form-control clean" name="sortInfo.wl_tablePrefix"/></td>
                                            <td class="text-right"><label class="control-label">分类编号：</label></td>
                                            <td><input type="text" class="form-control clean" name="sortInfo.wl_sortCode"/></td>
                                        </tr>
                                        <tr>
                                            <td class="text-right"><label class="control-label">表中文名：</label></td>
                                            <td><input type="text" class="form-control clean" name="sortInfo.wl_sortName"/></td>
                                            <td class="text-right"><label class="control-label">表英文名：</label></td>
                                            <td><input type="text" class="form-control clean" name="sortInfo.wl_infoTableName"/></td>
                                        </tr>
                                        <tr>
                                            <td class="text-right"><label class="control-label">对象别名：</label></td>
                                            <td><input type="text" class="form-control clean" name="sortInfo.wl_objName"/></td>
                                            <td class="text-right"><label class="control-label">当前状态：</label></td>
                                            <td>
                                                <select id="searchForm_sortStatus"  name="sortInfo.w_sortStatus" class="form-control  clean">
                                                    <option value="">--请选择--</option>
                                                    <option value="0">已停用</option>
                                                    <option value="1">启用中</option>
                                                </select>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>

                                <center>
                                    <div class="box-footer clearfix">
                                        <button type="button" class="btn btn-success"
                                                onclick="getTableData();"><i
                                                class="fa fa-search"></i> 查询
                                        </button>&nbsp;
                                        <button type="button" class="btn btn-warning"
                                                onclick="mytools.cleanData('#searchForm');">重置
                                        </button>&nbsp;
                                    </div>
                                </center>
                            </form>
                        </div>
                    </div>
                    <!-- 搜索 end -->

                    <div class="box box-success">
                        <!--列表title  start -->
                        <div class="box-header with-border">
                            <h3 class="box-title">数据表管理 [<span
                                    id="span-sysname-text"></span>] [共计<span
                                    id="span-datalist-total"></span>条数据]
                                　　　              <!--  <br/><br/>
                    <div role="toolbar" class="btn-toolbar">
				     <div class="btn-group">-->
                                <button data-step="1" data-intro="点此按钮增加功能业务表" aria-label="Left Align" class="btn btn-success"
                                        type="button" onclick="toAdd();"><i
                                        class="fa fa-plus-circle"></i> 增加新表
                                </button>&nbsp;&nbsp;
                                <button type="button" class="btn btn-danger"
                                        onclick="initCache();">刷新缓存
                                </button>&nbsp;&nbsp;
                                <button type="button" id="btn-download-doc" class="btn btn-info hidden"
                                        onclick="downloadDoc();"><i class="fa fa-download"></i> 生成设计文档
                                </button>
                                <!--</div>
                              </div>-->
                            </h3>
                            <div class="box-tools pull-right">
                                　　　　　　　　
                                <button type="button" class="btn btn-box-tool"
                                        data-widget="collapse"><i class="fa fa-minus"></i>
                                </button>
                            </div>
                        </div>

                        <!-- /.box-header -->
                        <div class="box-body">
                            <table id="dataList" class="table table-bordered table-hover">
                                <thead class="bg-success">
                                <tr>
                                    <th>表名前缀</th>
                                    <th>分类编号</th>
                                    <th>表中文名</th>
                                    <th>表英文名</th>
                                    <th>对象别名</th>
                                    <th class="hidden">所属系统</th>
                                    <th>状态</th>
                                    <th data-step="2" data-intro="表新增完成后，选中需操作的表，先字段设计、再启用表。">操作</th>
                                </tr>
                                </thead>
                                <tbody id="dataList-body">
                                </tbody>
                            </table>
                            <center>
                                <ul id="dataList-page"></ul>
                            </center>
                        </div>

                    </div>
                </div>
            </div>
        </section>
        <!-- Main end -->


        <div class="modal fade" id="my_modal_add" tabindex="-1" role="dialog"
             aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title">
                            <font color="red">添加</font>&nbsp;
                        </h4>
                    </div>
                    <div class="modal-body">

                        <form class="form-horizontal" role="form" id="addForm" action="javascript:;">

                            <!-- 隐藏域 start -->
                            <input type="hidden" name="formToken" class="formToken" value=""/>
                            <input type="hidden" name="mainTab" value="1"/>
                            <input type="hidden" name="sortStatus" id="sortStatus" value="0"/>
                            <input type="hidden" name="sortDisable" value="0"/>
                            <input type="hidden" name="sortStatistics" value="0"/>
                            <input type="hidden" name="sysName" value=""/>

                            <!-- 隐藏域 end -->

                            <div class="box-body" id="submitFormData">

                                <!-- 属性循环体 start -->
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">数据库类型：</label>
                                    <div class="col-sm-8">
                                        <select name="databaseType" class="form-control">
                                            <option>--请选择--</option>
                                            <option value="oracle"
                                                    <c:if test="${database_type=='oracle'}">selected</c:if>>
                                                oracle
                                            </option>
                                            <option value="mysql"
                                                    <c:if test="${database_type=='mysql'}">selected</c:if>  >
                                                mysql
                                            </option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">表名前缀：</label>
                                    <div class="col-sm-8">
                                        <input type="text"
                                               data-bv-notempty="true" data-bv-notempty-message="此项不能为空"
                                               data-bv-regexp="true" data-bv-regexp-regexp="^[a-z]+$" data-bv-regexp-message="只能是小写英文字母"
                                               id="tablePrefix" name="tablePrefix"
                                               class="form-control clean" placeholder="只能是小写英文字母"
                                               onchange="setInfoTableName('addForm')"/>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">表英文名：</label>
                                    <div class="col-sm-8">
                                        <input type="text" id="sortCode" name="sortCode"
                                               data-bv-notempty="true" data-bv-notempty-message="此项不能为空"
                                               data-bv-regexp="true" data-bv-regexp-regexp="^[a-z_]+$" data-bv-regexp-message="只能是小写英文字母，多个单词使用下划线间隔！"
                                               class="form-control clean" maxlength="50"
                                               placeholder="只能是小写英文字母，多个单词使用下划线间隔！"
                                               onchange="setInfoTableName('addForm')"/>
                                    </div>
                                </div>


                                <div class="form-group">
                                    <label class="col-sm-3 control-label">表中文名：</label>
                                    <div class="col-sm-8">
                                        <input type="text" id="sortName" name="sortName" data-bv-notempty="true" data-bv-notempty-message="此项不能为空"
                                               class="form-control clean" placeholder="请输入数据表的中文名！"
                                               maxlength="30"/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">完整表名：</label>
                                    <div class="col-sm-8">
                                        <input type="text" name="infoTableName" id="infoTableName"
                                               value="" readonly="readonly"
                                               class="form-control clean" placeholder="自动生成完整表名"/>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">对象别名：</label>
                                    <div class="col-sm-8">
                                        <input type="text" id="objName" readonly="readonly"
                                               name="objName" class="form-control clean"
                                               placeholder="自动生成表对象名-驼峰式！"/>
                                    </div>
                                </div>

                                <!-- 属性循环体 end -->
                            </div>

                            <div class="box-footer">
                                <button type="button" class="btn btn-success pull-left"
                                        onclick="mytools.closeModal('my_modal_add');">取消
                                </button>
                                <button type="button" class="btn btn-danger pull-right"
                                        onclick="add('addForm');">提 交
                                </button>
                            </div>

                        </form>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
        </div>


        <div class="modal fade" id="my_modal_edit" tabindex="-1" role="dialog"
             aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title">
                            <font color="red">修改</font>&nbsp;
                        </h4>
                    </div>
                    <div class="modal-body">

                        <form class="form-horizontal" role="form" id="editForm" action="javascript:;">

                            <!-- 隐藏域 start -->
                            <input type="hidden" name="formToken" class="formToken"/>
                            <input type="hidden" name="sortId" class="clean" data-name="sortInfo.sortId"/>
                            <input type="hidden" data-name="infoTableName" class="clean" name="infoTableName"/>
                            <input type="hidden" name="sysName" class="clean"  data-name="sortInfo.sysName"/>
                            <!-- 隐藏域 end -->

                            <div class="box-body" id="submitFormData_editForm">

                                <!-- 属性循环体 start -->
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">表名前缀：</label>
                                    <div class="col-sm-8">
                                        <input type="text"
                                               data-bv-notempty="true" data-bv-notempty-message="此项不能为空"  placeholder="只能是小写英文字母"
                                               data-bv-regexp="true" data-bv-regexp-regexp="^[a-z]+$" data-bv-regexp-message="只能是小写英文字母"
                                               data-name="sortInfo.tablePrefix" name="tablePrefix"
                                               class="form-control clean"
                                               onchange="setInfoTableName('editForm')"/>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">分类编号：</label>
                                    <div class="col-sm-8">
                                        <input type="text" data-name="sortInfo.sortCode"
                                               data-bv-notempty="true" data-bv-notempty-message="此项不能为空" placeholder="只能是小写英文字母，，多个单词使用下划线间隔！"
                                               data-bv-regexp="true" data-bv-regexp-regexp="^[a-z_]+$" data-bv-regexp-message="只能是小写英文字母，多个单词使用下划线间隔！"
                                               name="sortCode" class="form-control clean"
                                               maxlength="50" placeholder="必填项"
                                               onchange="setInfoTableName('editForm')"/>
                                    </div>
                                </div>


                                <div class="form-group">
                                    <label class="col-sm-3 control-label">分类名称：</label>
                                    <div class="col-sm-8">
                                        <input type="text" data-name="sortInfo.sortName" name="sortName"
                                               data-bv-notempty="true" data-bv-notempty-message="此项不能为空"
                                               class="form-control clean" maxlength="30"/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">对象别名：</label>
                                    <div class="col-sm-8">
                                        <input type="text" readonly="readonly" data-name="sortInfo.objName"
                                               name="objName" class="form-control clean"/>
                                    </div>
                                </div>


                                <!-- 属性循环体 end -->

                            </div>

                            <div class="box-footer">
                                <button type="button" class="btn btn-success pull-left"
                                        onclick="mytools.closeModal('my_modal_edit');">取消
                                </button>
                                <button type="button" class="btn btn-danger pull-right"
                                        onclick="add('editForm');">提 交
                                </button>
                            </div>

                        </form>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
        </div>

        <div class="modal fade" id="my_modal_sql" tabindex="-1" role="dialog"
             aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title"><font color="red">sql脚本</font>&nbsp;</h4>
                    </div>
                    <div class="modal-body" id="dataBase_sql"></div>
                </div>
                <!-- /.modal-content -->
            </div>
        </div>
        <script>
            var iusPlateArrays = "${IusPlateStr}".split(',');
        </script>
        <script type="text/template" id="dataList-template">
            <? for ( var i = 0; i < rows.length; i++) {?>
            <tr>
                <th style="display:none;"><?=rows[i].sortInfo.sortId?></th>
                <td><?=(pageObj.currentPage-1)*10+(i+1)?>
                    .<?=strUtil.doNull(rows[i].sortInfo.tablePrefix,'')?></td>
                <td><?=strUtil.doNull(rows[i].sortInfo.sortCode,'')?></td>
                <td><?=strUtil.doNull(rows[i].sortInfo.sortName,'')?></td>
                <td><?=strUtil.doNull(rows[i].sortInfo.infoTableName,'')?></td>
                <td><?=strUtil.doNull(rows[i].sortInfo.objName,'')?></td>
                <td>
                    <?if(rows[i].sortInfo.sortStatus=='0'){?>已停用<?}else{?>启用中<?}?>
                </td>
                <td <?if(i==0){?>data-step="2" data-intro="表的各种操作均在此。一般先进行字段设计、再启用表。启用成功后，自动创建基本接口。"<?}?>>

                <?if(iusPlateArrays.indexOf(rows[i].sortInfo.infoTableName)==-1){?>
                    <?if(rows[i].sortInfo.sortStatus=="1"){?>
                    <button type="button" class="btn btn-danger btn-xs"
                            onclick="startOrStop('<?=rows[i].sortInfo.sortId?>','<?=rows[i].sortInfo.infoTableName?>','<?=rows[i].sortInfo.objName?>','stop')">
                        停用
                    </button>&nbsp;
                    <?}else{?>
                    <button type="button" class="btn btn-success btn-xs"
                            onclick="startOrStop('<?=rows[i].sortInfo.sortId?>','<?=rows[i].sortInfo.infoTableName?>','<?=rows[i].sortInfo.objName?>','start')">
                        启用
                    </button>&nbsp;
                    <button class="btn btn-warning btn-xs" type="button"
                            onclick="toEdit('<?=rows[i].sortInfo.sortId?>');"><i class="fa fa-pencil-square-o"></i>
                        修改
                    </button>&nbsp;
                    <button type="button" class="btn btn-danger btn-xs"
                            onclick="toDele('<?=rows[i].sortInfo.sortId?>','<?=rows[i].sortInfo.infoTableName?>');">
                        <i class="fa fa-remove"></i> 删除
                    </button>&nbsp;
                    <?}?>
                <?}?>
                    <button type="button" class="btn btn-success btn-xs"
                            onclick="toCreate('<?=rows[i].sortInfo.infoTableName?>','<?=rows[i].sortInfo.sortId?>')">
                        字段设计
                    </button>&nbsp;
                    <button type="button" class="btn btn-primary btn-xs"
                            onclick="toCache('','<?=rows[i].sortInfo.sortCode?>','<?=rows[i].sortInfo.sysName?>');">
                        查看缓存
                    </button>
                </td>
            </tr>
            <?}?>
        </script>

        <script>
            var clickMenu = "objName-table";
            var id, myPage, dataListId, searchFormId, isShowLog, objName, objId;
            myPage = 10;
            dataListId = "dataList";
            searchFormId = "searchForm";
            objName = "pubMetadata";
            objId = "infoId";
            isShowLog = true;
            var id;
            var defSysEname = strUtil.doNull(strUtil.getLocalStorage("sysEname"), "");
            var index_load = layer.load(1, {shade: false});

            $("#searchForm_sysName").val(defSysEname);
            $("#addSysParamForm").find("input[name='sysParamManager.sysName']").val(defSysEname);
            $("#addForm").find("input[name='sysName']").val(defSysEname);
            $("#span-sysname-text").text(defSysEname+"-"+strUtil.getLocalStorage("sysCname"));
            //var dictListMap = DictUtil.initDictAndDymic();
            $(function () {
                checkInitDataSource();
                //1、加载分页列表数据
                getTableData();
                //2、控制是否启用token
                //setToken();
                //请在下面补充其他初始化方法（如数据字典、页面加载数据等）
                layer.close(index_load);
            });


            //读取（查询、编辑）数据
            function toEdit(id) {
                mytools.cleanData('#submitFormData_editForm');//情况模态窗口内数据
                setToken();
                var paramLoadData = {"sortInfo.w_sortId": id, "pageName": "objName-table","formName":"searchForm"};
                $.ajax({
                    type: 'get',
                    url: common_info_url,
                    data: paramLoadData,
                    dataType: "json",
                    success: function (myData) {
                        FormUtil.loadView("sortInfo", myData["sortInfo"]);
                        $("#my_modal_edit").modal("show");
                    }
                });
            }

            //逻辑删除
            function toDele(id, tableName) {
                var index_submit = layer.confirm("<font color=\"red\"><i class=\"fa fa-warning\"></i> 严重警告！删除不可恢复！</font><br/>您确定要删除【" + tableName + "】表吗？", {
                        btn: ['Yes', 'No'],
                        closeBtn: 0,
                        offset: '220px'
                    }
                    , function () {
                        layer.close(index_submit);
                        var paramLoadData = {"sortId": id};
                        doDele(paramLoadData);
                    });
            }

            function toCreate(tableName, sortId) {
                if (tableName && sortId) {
                    var url = "${page_admin}/project/objName-table-column?tableName=" + tableName + "&sortId=" + sortId +"&page=" + pageObj.currentPage;
                    mytools.pjax(url);
                }
            }

            function setInfoTableName(formId) {

                var sysCode = $("#" + formId).find("input[name='tablePrefix']").val();//$("#" + formId + " #tablePrefix").val();
                var sortCode = $("#" + formId).find("input[name='sortCode']").val();//$("#" + formId + " #sortCode").val();
                var tableName = sysCode + "_" + sortCode;
                $("#" + formId).find("input[name='infoTableName']").val(tableName);
                // $("#" + formId + " #infoTableName").val(tableName);
                $("#" + formId).find("input[name='objName']").val(sysCode + tranformStr1(sortCode));
                // $("#" + formId + " #objName").val(sysCode + tranformStr1(sortCode));

            }

            //字符串转成驼峰的方法
            function transformStr3(str) {
                var re = /_(\w)/g;
                return str.replace(re, function ($0, $1) {
                    return $1.toUpperCase();
                });
            }

            //首字母大写
            function tranformStr1(str) {
                var strArr = transformStr3(str);
                strArr = strArr.charAt(0).toUpperCase() + strArr.substring(1);
                return strArr;
            }

            //批量保存IUS常用接口参数数据
            function saveBatchSysParam(tableName, objName) {
                var index_load = layer.msg("正在初始化基本接口参数");
                var pageNameVal = tableName;
                var objNameVal = objName;
                pageNameVal = pageNameVal.replace(/_/g, "-");//  replace(regex_p,"");
                var paramData = {
                    "pageName": "sys-param-manager",
                    "formName": "searchForm",
                    "sysParamManager.w_sysName": defSysEname,
                    "sysParamManager.w_pageName": pageNameVal,
                    "sysParamManager.w_formName": "addForm"
                };
                //校验ius接口重复
                var flag = checkIusIsExist(paramData);

                if (flag) {
                    $("#addSysParamForm").find("input[name='sysParamManager.pageName']").val(pageNameVal);
                    $("#addSysParamForm").find("input[name='sysParamManager.modelTypes']").each(function () {
                        var oldVal = $(this).val();
                        var newVal = oldVal.split("_")[0] + "_" + objNameVal;
                        $(this).val(newVal);
                    });
                    $.ajax({
                        type: "post",
                        url: common_submit_url,
                        data: $("#addSysParamForm").serialize(),
                        dataType: "json",
                        success: function (myData) {
                            //console.log(myData);
                            layer.close(index_load);
                            if (myData.flag == "T") {
                                layer.msg("启用成功，接口初始化完成！");
                            } else {
                                layer.alert(myData.msg);
                            }

                        }
                    });
                } else {
                    layer.msg("启用成功，接口已存在！");
                    layer.close(index_load);
                }

            }

            function checkIusIsExist(paramData) {
                var flag = false;
                $.ajax({
                    type: "get",
                    url: common_list_url,
                    data: paramData,
                    async: false,
                    dataType: "json",
                    success: function (myData) {
                        // console.log(myData);
                        if (myData.total == 0) {
                            flag = true;
                        }
                    }
                });
                return flag;
            }

            $(function () {
                $('#' + dataListId + ' tbody').on('click', 'tr', function (e) {
                    if ($(this).hasClass('selected')) {
                        //$(this).removeClass('selected');
                    }
                    else {
                        $('tr.selected').removeClass('selected');
                        $(this).addClass('selected');
                    }
//                    id = $('tr.selected td').eq(0).html();
                    //  console.log($('tr.selected td').eq(1).html())
                });
            });

            //加载列表数据
            function getTableData() {
                var index_load = layer.load(1, {shade: false});
                $.ajax({
                    type: 'get',
                    url: common_list_url,
                    data: $("#" + searchFormId).serialize() + getCurrentPage(common_list_url + "?" + $("#" + searchFormId).serialize(), myPage),
                    dataType: 'json',
                    success: function (myData) {
                        console.log("myData",myData);
                        $("#span-datalist-total").text(myData.total);
                        if(myData.total*1>0){
                            $("#btn-download-doc").removeClass("hidden");
                        }else{
                            $("#btn-download-doc").addClass("hidden");
                        }
                        var data = baidu.template(dataListId + "-template", eval(myData));
                        $("#" + dataListId + "-body").html(data);
                        var option = {
                            ele: $("#" + dataListId + "-page")[0],
                            total: myData.total,
                            fn: getTableData,
                            url: common_list_url + "?" + $("#" + searchFormId).serialize()
                        }
                        generatePages(option);

                        layer.close(index_load);
                        initGuideIntroJs();
                    }
                });
            }

            //给模态窗口内form表单内的所有支持必填项的元素注入校验
            $(".modal").on('shown.bs.modal', function () {
                $(this).find("form").each(function(){
                    var formId = $(this).attr("id");
                    if(!strUtil.isNull(formId)){
                        formId="#"+formId;
                        console.log("formId",formId);
                        setValidate(formId);//定义add表单验证属性
                        mytools.cleanValidate(formId);//清空上次校验规则提示
                    }
                });
            });

            //设置token
            function setToken(){
                $.ajax({
                    type:'get',
                    url:'${ctx}/sendPage/token?token=true',
                    dataType:'text',
                    success: function(myData){
                        console.log(myData);
                        $('.formToken').val(myData);
                    }
                });
            }

            function toAdd() {
                mytools.cleanData('#submitFormData');//情况模态窗口内数据
                setToken();
                var tpfix = defSysEname;
                if ("plateform" == defSysEname) {
                    tpfix = "sys";
                } else {
                    if (!strUtil.isNull(defSysEname) && defSysEname.length > 2) {
                        tpfix = defSysEname.substring(0, 2);
                    }
                }

                $("#addForm").find("input[name='tablePrefix']").val(tpfix);
                $('#my_modal_add').modal('show');
                $("#sortCode").focus();
//                $("#addForm_sysName").val(defSysEname);
//                if (!strUtil.isNull(defSysEname)) {
//                    $("#addForm_sysName").attr("readOnly", true);
//                }
            }

            function initCache() {
                $.ajax({ type:'post',dataType:'json',
                    url:common_cache_url+"init",
                    data:{"pageName":"objName-table","formName":"initiCacheForm","sortInfo.w_sysName":defSysEname},
                    success: function(myData){
                        layer.close(index_load);
                        if(myData.flag=='T'){
                            layer.msg("刷新缓存成功！");
                        }else{
                            layer.msg("刷新缓存失败！");
                        }
                        console.log("iusCache.init",myData);
                    }
                });
            }

            //下载数据库设计文档
            function downloadDoc() {
                var layer_msg = layer.msg("正在生成数据库设计文档！");
                $.ajax({
                    type: 'post',
                    url: ctx+"/common/coding/createDataBaseDoc",
                    data: {"sysEname":defSysEname,"databaseType":"${database_type}"},
                    dataType: "json",
                    success: function (myData) {
                       console.log(myData);
                       if(myData.flag=="T"){
                           var jdata = jQuery.parseJSON(myData.msg);
                           var fileNameDoc= jdata.fileNameDoc;
                           var fileNameHtml = jdata.fileNameHtml;
                           var download_doc= jdata.downloadDoc;
                           var download_html= jdata.downloadHtml;
                           layer.confirm("数据库设计文档创建完成！<p><a href='"+download_html+"' title='点击预览网页版' target='_blank' class='red'>《"+fileNameDoc+"》</a></p>", {
                               btn: ['点击下载','取消'] //按钮
                           }, function(){
                               window.open(download_doc);
                               layer.closeAll();
                               index_msg=layer.msg("工程正在下载中...");
                           }, function(){
                               layer.closeAll();
                           });
                       }else{
                           layer.alert(myData.msg);
                       }
                    }
                });
            }


            //删除信息（逻辑删除）
            function doDele(paramData) {
                var index_load = layer.load(1, {shade: false});
                $.ajax({
                    type: "get",
                    url: "${ctx}/info/delInfo",
                    data: paramData,
                    dataType: "json",
                    success: function (myData) {
                        var result = myData.flag;
                        layer.close(index_load);
                        if (result == "T") {
                            layer.alert("删除操作成功");
                            refresh();
                        } else {
                            layer.alert(myData.msg);
                        }
                    }
                });
            }

            /**
             * 表单数据提交
             * @param formId
             */
            function add(formId) {
                //校验规则-表单提交时触发
                var validate = $('#' + formId).data('bootstrapValidator').validate();
                console.log("validate",validate);
                if (!validate.isValid()) { //如果校验不通过就返回
                    return;
                }

                var index_submit = layer.confirm('您确定要提交信息吗？', {
                        btn: ['Yes', 'No'],
                        closeBtn: 0,
                        offset: '220px'
                    }
                    , function () {
                        layer.close(index_submit);
                        $.ajax({
                            type: "post",
                            url: "${ctx}/info/saveInfo",
                            data: $("#" + formId).serialize(),
                            dataType: "json",
                            success: function (myData) {
                                //console.log(myData);
                                if (myData.flag == "T") {
                                    layer.alert("数据操作成功");
                                    if ("addForm" == formId) {
                                        $("#my_modal_add").modal("hide");
                                    } else {
                                        $("#my_modal_edit").modal("hide");
                                    }
                                } else {
                                    layer.alert(myData.msg);
                                }
                                //validate.resetForm();//提交成功后，删除校验方法
                                refresh();
                            }
                        });
                    });
            }

            function startOrStop(sortId, tableName, objName, type) {
                var url = "${ctx}/info/publish";
                var cmsg = "您确定要启用表[" + tableName + "]吗？";
                if ("start" == type) {
                    var cflag = checkPrimaryKeyCount(sortId);
                    //alert(cflag);
                    if (!cflag) {
                        return;
                    }
                }
                if ("stop" == type) {
                    cmsg = "<font color='red'><i class='fa fa-warning'></i>表单停用将删除表中所有数据！</font><br/>您确定要停用表[" + tableName + "]吗？";
                    url = '${ctx}/info/stop';
                }
                var index_submit = layer.confirm(cmsg, {
                        btn: ['Yes', 'No'],
                        closeBtn: 0,
                        offset: '220px'
                    }
                    , function () {
                        layer.close(index_submit);
                        var index_load = layer.load(1, {shade: false});
                        $.ajax({
                            type: "get",
                            url: url,
                            data: {"sortId": sortId},
                            dataType: "json",
                            success: function (myData) {
                                layer.close(index_load);
                                console.log(myData);
                                if (myData.flag == "T") {
                                    if (type == 'start') {
                                        saveBatchSysParam(tableName, objName);
                                    } else {
                                        layer.alert("数据表操作成功");
                                    }

                                } else {
                                    layer.alert(myData.msg);
                                }
                                refresh();
                            }
                        });
                    });
            }

            function checkPrimaryKeyCount(sortId) {
                var paramData = {};
                paramData["pageName"] = "objName-table-column";
                paramData["formName"] = "searchForm";
                paramData["metadata.w_sortId"] = sortId;
                paramData["metadata.wi_dataRestrict"] = "1,4";
                var resultFlag = false;
                $.ajax({
                    type: 'get',
                    url: common_list_url,
                    data: paramData,
                    async: false,
                    dataType: 'json',
                    success: function (myData) {
                        console.log(myData);
                        if (myData.flag == "T" && myData.total > 0) {
                            var pkeyMap = {};
                            for (var i = 0; i < myData.rows.length; i++) {
                                var objKey = myData.rows[i].dataRestrict;
                                if (pkeyMap.hasOwnProperty(objKey)) {
                                    pkeyMap[objKey] = pkeyMap[objKey] + 1;
                                } else {
                                    pkeyMap[objKey] = 1;
                                }
                            }
                            var len = Object.keys(pkeyMap).length;
                            console.log(pkeyMap)
                            if (1 == len) {
                                for (var key in pkeyMap) {
                                    if (key == "1" && pkeyMap[objKey] * 1 > 1) {
                                        layer.msg("主键字段不能设置多个！");
                                        resultFlag = false;
                                    } else if (key == "4" && pkeyMap[objKey] * 1 < 2) {
                                        layer.msg("联合主键字段至少为两个及以上！");
                                        resultFlag = false;
                                    } else {
                                        resultFlag = true;
                                    }
                                }
                            } else if (len > 1) {
                                layer.msg("主键字段和联合主键字段不能同时存在！");
                                resultFlag = false;
                            } else {
                                resultFlag = true;
                            }
                        }else{
                            layer.msg("请先进行字段设计！");
                        }
                    }
                });
                return resultFlag;
            }

            function refresh() {
                getTableData();
            }

            //自定义方法
            //1.定义校验规则-定义
            function setValidate(id) {
                $(id).bootstrapValidator({
                    feedbackIcons: {
                        valid: 'glyphicon glyphicon-ok',
                        invalid: 'glyphicon glyphicon-remove',
                        validating: 'glyphicon glyphicon-refresh'
                    }, /** 以下需要结合实际业务清空补充个表单元素的验证规则 **/
                    fields: {
                        /**
                        "tablePrefix": {
                            validators: {
                                notEmpty: {
                                    message: '自定义属性不能为空！'
                                },
                                regexp: {
                                    regexp: /^[a-z]+$/,
                                    message: '只能是小写英文字母！'
                                }
                            }
                        },
                        "sortCode": {
                            validators: {
                                notEmpty: {
                                    message: '自定义属性不能为空！'
                                },
                                regexp: {
                                    regexp: /^[a-z_ ]+$/,
                                    message: '只能是小写英文字母，多个单词使用下划线间隔！'
                                }
                            }
                        },
                        "sortName": {
                            validators: {
                                notEmpty: {
                                    message: '自定义属性不能为空！'
                                }
                            }
                        },
                        "objName": {
                            validators: {
                                notEmpty: {
                                    message: '自定义属性不能为空！'
                                },
                                regexp: {
                                    regexp: /^[a-zA-Z]+$/,
                                    message: '请填写英文数据表名-驼峰式！'
                                }
                            }
                        },**/
                    }
                });
            }

            function toCache(cacheSpaceName, sortCode) {
                var cachekey = sortCode + "_" + defSysEname + "_tableAttr";
                $.ajax({
                    type: 'get',
                    url: common_cache_url+"view",
                    data:{"cacheSpaceName":cacheSpaceName,"cachekey":cachekey},
                    dataType: 'json',
                    success: function (myData) {
                        console.log(myData);
                        if (myData.flag == "T") {
                            layer.open({
                                title: '查看缓存信息',
                                type: 1,
                                skin: 'layui-layer-demo', //样式类名
                                anim: 2,
                                shadeClose: true, //开启遮罩关闭
                                area: ['500px', '300px'],
                                content: "<div style='word-break:break-all;word-wrap:break-word;width:100%;padding:5px;'>" + myData.msg +"</div>"
                            });
                        } else {
                            layer.alert(myData.msg);
                        }
                    }
                });
            }

            function checkInitDataSource() {
                if(strUtil.isNull(defSysEname)){
                    return;
                }
                $.ajax({ type:'get', url:common_list_url,dataType:'json',
                    data:{'pageName':'datasource-list','formName':'searchForm','tRpcDatasource.w_sysEname':defSysEname},
                    success: function(myData){
                        console.log("datasource",myData);
                        if(myData.total==0){
                            if(window.location.host.indexOf("portal.iussoft.com")>-1){
                                //添加测试数据源。
                                mytools.addTestDatasource("${database_type}",defSysEname);
                            }else{
                                layer.confirm('您还未配置数据源，是否配置默认的数据源！', {closeBtn: 0,btn: ['是','否，我自己设置']},
                                    function(){
                                        //添加测试数据源。
                                        mytools.addTestDatasource("${database_type}",defSysEname);
                                    }, function(){
                                        mytools.pjax("${page_admin}/project/datasource-list?sysEname="+defSysEname);
                                    });
                            }

                        }
                    }
                });
            }

            //判断是否第一次进入，启用步骤引导提示
            function initGuideIntroJs() {
                if(strUtil.isNull(strUtil.getLocalStorage("_iussoft_intro_project_objname"))){
                    strUtil.setLocalStorage("_iussoft_intro_project_objname","T");
                    showGuideIntroJs();
                }
//                var _cookie_intro_flag= $.cookie('_iussoft_intro_project_objname');
//                //console.log("_iussoft_intro_project_objname",_cookie_intro_flag);
//                if(strUtil.isNull(_cookie_intro_flag)){
//                    $.cookie('_iussoft_intro_project_objname', "T");
//                    showGuideIntroJs();
//                }
            }

        </script>

    </div>
    <!-- /.content-wrapper -->
    <!-- foot start -->
    <%@include file="/common/plateform/foot.jsp" %>
    <!-- foot start -->
</div>


</body>


</html>

